﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Shell.xaml.cs" company="WordSteps.com">
//   All rights reserved
// </copyright>
// <summary>
//   Interaction logic for shell.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace RapidDict
{
    using System.Configuration;
    using Infrastructure.Interfaces;

    /// <summary>
    /// Interaction logic for shell.xaml
    /// </summary>
    public partial class Shell : IAppViewService
    {
        private bool isAppExiting = false;

        public Shell()
        {
            this.InitializeComponent();
            this.Title = ConfigurationSettings.AppSettings["ApplicationTitle"].ToString();
        }

        public void ShowApp()
        {
            this.Show();
            this.Activate();
        }

        public void HideApp()
        {
            this.Hide();
        }

        public void CloseApp()
        {
            this.isAppExiting = true;
            this.Close();
        }

        public void ChangeVisibility()
        {
            if (this.Visibility == System.Windows.Visibility.Hidden)
            {
                this.ShowApp();
            }
            else
            {
                this.HideApp();
            }
        }

        public void HandleClosing(System.ComponentModel.CancelEventArgs e)
        {
            // When the application is closed, check weather the application is
            // exiting from menu or from close button
            if (!this.isAppExiting)
            {
                // if the forms close button is triggered, cancel the event and hide the form
                e.Cancel = true;
                this.HideApp();
            }
        }

        public void ChangeAlwaysOnTopMode()
        {
            if (this.Topmost)
            {
                this.Topmost = false;
            }
            else
            {
                this.Topmost = true;
            }
        }

        public bool IsAlwaysOnTop()
        {
            return this.Topmost;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.HandleClosing(e);
        }
    }
}
